Introduction:

Line following robot is an autonomous robot that can follow a path. Usually black line in white background and vice versa are used as the path for the robot.

It is a simple DIY project that suitable for beginners. Line following robot is one of the common project which the hobbyists are doing. Basic knowledge in electronics and c programming are need for the making of this project. The basic working principle is, sensing the line continuously and gives feedback to processor to correct the path if it is not in the correct way. Practical applications are : automated cars running on roads, industrial robots etc.

 

Materials required:

  • Arduino: This is the brain of the line follower. All the decisions are taken by the arduino according to the feedback from sensors. Arduino is an open source electronic platform. Here we are using Arduino UNO board.
  • Motor Driver (L298/293): Motors are not directly connected since it doesn’t meet current requirements. So that it is connected to motor driver and to arduino.
  •  Motor: Here we are using geared DC motor. They are the main actuators for our robot.
  • Sensor array: This would the main source for feedback on the whereabouts of the robot with respect to line. Here we are using light dependent resistor (LDR) as sensor & LED is used as the light source.
  • Power supply: 6V 4.5A battery regulated to 5V using a motor driver module.
  • Wheels & Castor wheels: 5cm diameter
  • Metal chassis
  • Jumper wires

Construction:

Two motors are attached at the either side of the metal chassis. Castor wheel is fixed at in front. Use DC motors with 100 RPM so as to reduce the speed. The robot using sensor array of 5 LDRs & LEDs which are facing the ground.

                                

Fix the sensor array plate in front of the metal chassis. The output of the LDR is analog value which is given to the 5 analog pins of the arduino. Analog value depends on the amount of light reflected back.  

Arduino Code:


int s1=0;
int s2=0;
int s3=0;
int s4=0;
int s5=0;

void setup()

{pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
Serial.begin(9600);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
}

void left(int rl)

{  
 digitalWrite(6,LOW);
 digitalWrite(5,HIGH);
 digitalWrite(8,HIGH);
 digitalWrite(7,LOW);
 delay(40+rl); 
 digitalWrite(5,LOW);
 digitalWrite(6,LOW);
 digitalWrite(7,LOW);
 digitalWrite(8,LOW);  }

 
void forward(int rf)
{ //forward
    digitalWrite(5,HIGH);
 digitalWrite(6,LOW);
 digitalWrite(7,HIGH);
 digitalWrite(8,LOW);
 delay(100+rf); 
  digitalWrite(5,LOW);
 digitalWrite(6,LOW);
 digitalWrite(7,LOW);
 digitalWrite(8,LOW); }

void right(int rf)
{
 digitalWrite(6,HIGH);
 digitalWrite(5,LOW);
 digitalWrite(8,LOW);
 digitalWrite(7,HIGH);
 delay(40+rf); 
 digitalWrite(5,LOW);
 digitalWrite(6,LOW);
 digitalWrite(7,LOW);
 digitalWrite(8,LOW); }

void loop() {
   Serial.print("sensor1 = " );                       
  Serial.print(s1); 
  Serial.print("\n" ); 
  Serial.print("sensor2 = " );                       
  Serial.print(s2); 
  Serial.print("\n" ); 
  Serial.print("sensor3 = " );                       
  Serial.print(s3); 
  Serial.print("\n" );
  Serial.print("sensor4 = " ); 
 Serial.print(s4); 
  Serial.print("\n" ); 
   Serial.print("sensor5 = " );
  Serial.print(s5); 
  Serial.print("\n" ); 
 
  s1 = analogRead(A0);  
  delay(2); 
  s2 = analogRead(A1);
  delay(2);
  s3 = analogRead(A2);     
  delay(2);
   s4 = analogRead(A3);  
  delay(2); 
   s5 = analogRead(A4);  
  delay(2); 
  
  if((s1<=150)&&(s5<=150))
forward(40);

   
else if((s1<=150)&&(s2<=150)&&(s3<=180))
left(360);

else if((s5<=250)&&(s4<=250)&&(s3<=180))
right(360);

else if(s1 <=150)
  left(50);
 
 
else if(s2 <=150)
 left(0);
 
 
else if(s3 <=180)
 forward(0);
 
 else if(s5 <=250)
 right(50);
 
 else if(s4 <=250)
 right(0);
 
 else
 forward(0);
 }
  
Related Items